
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/series/series.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:17 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Series Expansions &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../" id="documentation_options" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../live.sympy.org/static/live-sphinx.js"></script>
    <script async="async" src="../../../../cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest8331.js?config=TeX-AMS_HTML-full"></script>
    <script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]]}})</script>
    
    <link rel="shortcut icon" href="../../_static/sympy-notailtext-favicon.ico"/>
    <link href="series.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="Sequences" href="sequences.html" />
    <link rel="prev" title="Series" href="index.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="sequences.html" title="Sequences"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Series"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" accesskey="U">Series</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Series Expansions</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="series-expansions">
<span id="id1"></span><h1>Series Expansions<a class="headerlink" href="#series-expansions" title="Permalink to this headline">¶</a></h1>
<section id="limits">
<h2>Limits<a class="headerlink" href="#limits" title="Permalink to this headline">¶</a></h2>
<p>The main purpose of this module is the computation of limits.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.limits.limit">
<span class="sig-prename descclassname"><span class="pre">sympy.series.limits.</span></span><span class="sig-name descname"><span class="pre">limit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/limits.py#L11-L62"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.limits.limit" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the limit of <code class="docutils literal notranslate"><span class="pre">e(z)</span></code> at the point <code class="docutils literal notranslate"><span class="pre">z0</span></code>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>e</strong> : expression, the limit of which is to be taken</p>
<p><strong>z</strong> : symbol representing the variable in the limit.</p>
<blockquote>
<div><p>Other symbols are treated as constants. Multivariate limits
are not supported.</p>
</div></blockquote>
<p><strong>z0</strong> : the value toward which <code class="docutils literal notranslate"><span class="pre">z</span></code> tends. Can be any expression,</p>
<blockquote>
<div><p>including <code class="docutils literal notranslate"><span class="pre">oo</span></code> and <code class="docutils literal notranslate"><span class="pre">-oo</span></code>.</p>
</div></blockquote>
<p><strong>dir</strong> : string, optional (default: “+”)</p>
<blockquote>
<div><p>The limit is bi-directional if <code class="docutils literal notranslate"><span class="pre">dir=&quot;+-&quot;</span></code>, from the right
(z-&gt;z0+) if <code class="docutils literal notranslate"><span class="pre">dir=&quot;+&quot;</span></code>, and from the left (z-&gt;z0-) if
<code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;</span></code>. For infinite <code class="docutils literal notranslate"><span class="pre">z0</span></code> (<code class="docutils literal notranslate"><span class="pre">oo</span></code> or <code class="docutils literal notranslate"><span class="pre">-oo</span></code>), the <code class="docutils literal notranslate"><span class="pre">dir</span></code>
argument is determined from the direction of the infinity
(i.e., <code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;</span></code> for <code class="docutils literal notranslate"><span class="pre">oo</span></code>).</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">limit</span><span class="p">,</span> <span class="n">sin</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> <span class="c1"># default dir=&#39;+&#39;</span>
<span class="go">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">dir</span><span class="o">=</span><span class="s2">&quot;-&quot;</span><span class="p">)</span>
<span class="go">-oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">dir</span><span class="o">=</span><span class="s1">&#39;+-&#39;</span><span class="p">)</span>
<span class="go">zoo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">limit</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">oo</span><span class="p">)</span>
<span class="go">0</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>First we try some heuristics for easy and frequent cases like “x”, “1/x”,
“x**2” and similar, so that it’s fast. For all other cases, we use the
Gruntz algorithm (see the gruntz() function).</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="limitseq.html#sympy.series.limitseq.limit_seq" title="sympy.series.limitseq.limit_seq"><code class="xref py py-obj docutils literal notranslate"><span class="pre">limit_seq</span></code></a></dt><dd><p>returns the limit of a sequence.</p>
</dd>
</dl>
</div>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.series.limits.Limit">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.series.limits.</span></span><span class="sig-name descname"><span class="pre">Limit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/limits.py#L127-L354"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.limits.Limit" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents an unevaluated limit.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Limit</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Limit</span><span class="p">(</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">Limit(sin(x)/x, x, 0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Limit</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">dir</span><span class="o">=</span><span class="s2">&quot;-&quot;</span><span class="p">)</span>
<span class="go">Limit(1/x, x, 0, dir=&#39;-&#39;)</span>
</pre></div>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.series.limits.Limit.doit">
<span class="sig-name descname"><span class="pre">doit</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">hints</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/limits.py#L197-L354"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.limits.Limit.doit" title="Permalink to this definition">¶</a></dt>
<dd><p>Evaluates the limit.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>deep</strong> : bool, optional (default: True)</p>
<blockquote>
<div><p>Invoke the <code class="docutils literal notranslate"><span class="pre">doit</span></code> method of the expressions involved before
taking the limit.</p>
</div></blockquote>
<p><strong>hints</strong> : optional keyword arguments</p>
<blockquote>
<div><p>To be passed to <code class="docutils literal notranslate"><span class="pre">doit</span></code> methods; only used if deep is True.</p>
</div></blockquote>
</dd>
</dl>
</dd></dl>

</dd></dl>

<p>As is explained above, the workhorse for limit computations is the
function gruntz() which implements Gruntz’ algorithm for computing limits.</p>
<section id="the-gruntz-algorithm">
<h3>The Gruntz Algorithm<a class="headerlink" href="#the-gruntz-algorithm" title="Permalink to this headline">¶</a></h3>
<p>This section explains the basics of the algorithm used for computing limits.
Most of the time the limit() function should just work. However it is still
useful to keep in mind how it is implemented in case something does not work
as expected.</p>
<p>First we define an ordering on functions. Suppose <span class="math notranslate nohighlight">\(f(x)\)</span> and <span class="math notranslate nohighlight">\(g(x)\)</span> are two
real-valued functions such that <span class="math notranslate nohighlight">\(\lim_{x \to \infty} f(x) = \infty\)</span> and
similarly <span class="math notranslate nohighlight">\(\lim_{x \to \infty} g(x) = \infty\)</span>. We shall say that <span class="math notranslate nohighlight">\(f(x)\)</span>
<em>dominates</em>
<span class="math notranslate nohighlight">\(g(x)\)</span>, written <span class="math notranslate nohighlight">\(f(x) \succ g(x)\)</span>, if for all <span class="math notranslate nohighlight">\(a, b \in \mathbb{R}_{&gt;0}\)</span> we have
<span class="math notranslate nohighlight">\(\lim_{x \to \infty} \frac{f(x)^a}{g(x)^b} = \infty\)</span>.
We also say that <span class="math notranslate nohighlight">\(f(x)\)</span> and
<span class="math notranslate nohighlight">\(g(x)\)</span> are <em>of the same comparability class</em> if neither <span class="math notranslate nohighlight">\(f(x) \succ g(x)\)</span> nor
<span class="math notranslate nohighlight">\(g(x) \succ f(x)\)</span> and shall denote it as <span class="math notranslate nohighlight">\(f(x) \asymp g(x)\)</span>.</p>
<p>Note that whenever <span class="math notranslate nohighlight">\(a, b \in \mathbb{R}_{&gt;0}\)</span> then
<span class="math notranslate nohighlight">\(a f(x)^b \asymp f(x)\)</span>, and we shall use this to extend the definition of
<span class="math notranslate nohighlight">\(\succ\)</span> to all functions which tend to <span class="math notranslate nohighlight">\(0\)</span> or <span class="math notranslate nohighlight">\(\pm \infty\)</span> as <span class="math notranslate nohighlight">\(x \to \infty\)</span>.
Thus we declare that <span class="math notranslate nohighlight">\(f(x) \asymp 1/f(x)\)</span> and <span class="math notranslate nohighlight">\(f(x) \asymp -f(x)\)</span>.</p>
<p>It is easy to show the following examples:</p>
<ul class="simple">
<li><p><span class="math notranslate nohighlight">\(e^x \succ x^m\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(e^{x^2} \succ e^{mx}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(e^{e^x} \succ e^{x^m}\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(x^m \asymp x^n\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(e^{x + \frac{1}{x}} \asymp e^{x + \log{x}} \asymp e^x\)</span>.</p></li>
</ul>
<p>From the above definition, it is possible to prove the following property:</p>
<blockquote>
<div><p>Suppose <span class="math notranslate nohighlight">\(\omega\)</span>, <span class="math notranslate nohighlight">\(g_1, g_2, \ldots\)</span> are functions of <span class="math notranslate nohighlight">\(x\)</span>,
<span class="math notranslate nohighlight">\(\lim_{x \to \infty} \omega = 0\)</span> and <span class="math notranslate nohighlight">\(\omega \succ g_i\)</span> for
all <span class="math notranslate nohighlight">\(i\)</span>. Let <span class="math notranslate nohighlight">\(c_1, c_2, \ldots \in \mathbb{R}\)</span> with <span class="math notranslate nohighlight">\(c_1 &lt; c_2 &lt; \cdots\)</span>.</p>
<p>Then <span class="math notranslate nohighlight">\(\lim_{x \to \infty} \sum_i g_i \omega^{c_i} = \lim_{x \to \infty} g_1 \omega^{c_1}\)</span>.</p>
</div></blockquote>
<p>For <span class="math notranslate nohighlight">\(g_1 = g\)</span> and <span class="math notranslate nohighlight">\(\omega\)</span> as above we also have the following easy result:</p>
<blockquote>
<div><ul class="simple">
<li><p><span class="math notranslate nohighlight">\(\lim_{x \to \infty} g \omega^c = 0\)</span> for <span class="math notranslate nohighlight">\(c &gt; 0\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\lim_{x \to \infty} g \omega^c = \pm \infty\)</span> for <span class="math notranslate nohighlight">\(c &lt; 0\)</span>,
where the sign is determined by the (eventual) sign of <span class="math notranslate nohighlight">\(g\)</span></p></li>
<li><p><span class="math notranslate nohighlight">\(\lim_{x \to \infty} g \omega^0 = \lim_{x \to \infty} g\)</span>.</p></li>
</ul>
</div></blockquote>
<p>Using these results yields the following strategy for computing
<span class="math notranslate nohighlight">\(\lim_{x \to \infty} f(x)\)</span>:</p>
<ol class="arabic simple">
<li><p>Find the set of <em>most rapidly varying subexpressions</em> (MRV set) of <span class="math notranslate nohighlight">\(f(x)\)</span>.
That is, from the set of all subexpressions of <span class="math notranslate nohighlight">\(f(x)\)</span>, find the elements that
are maximal under the relation <span class="math notranslate nohighlight">\(\succ\)</span>.</p></li>
<li><p>Choose a function <span class="math notranslate nohighlight">\(\omega\)</span> that is in the same comparability class as
the elements in the MRV set, such that <span class="math notranslate nohighlight">\(\lim_{x \to \infty} \omega = 0\)</span>.</p></li>
<li><p>Expand <span class="math notranslate nohighlight">\(f(x)\)</span> as a series in <span class="math notranslate nohighlight">\(\omega\)</span> in such a way that the antecedents of
the above theorem are satisfied.</p></li>
<li><p>Apply the theorem and conclude the computation of
<span class="math notranslate nohighlight">\(\lim_{x \to \infty} f(x)\)</span>, possibly by recursively working on <span class="math notranslate nohighlight">\(g_1(x)\)</span>.</p></li>
</ol>
<section id="notes">
<h4>Notes<a class="headerlink" href="#notes" title="Permalink to this headline">¶</a></h4>
<p>This exposition glossed over several details. Many are described in the file
gruntz.py, and all can be found in Gruntz’ very readable thesis. The most
important points that have not been explained are:</p>
<ol class="arabic simple">
<li><p>Given f(x) and g(x), how do we determine if <span class="math notranslate nohighlight">\(f(x) \succ g(x)\)</span>,
<span class="math notranslate nohighlight">\(g(x) \succ f(x)\)</span> or <span class="math notranslate nohighlight">\(g(x) \asymp f(x)\)</span>?</p></li>
<li><p>How do we find the MRV set of an expression?</p></li>
<li><p>How do we compute series expansions?</p></li>
<li><p>Why does the algorithm terminate?</p></li>
</ol>
<p>If you are interested, be sure to take a look at
<a class="reference external" href="http://www.cybertester.com/data/gruntz.pdf">Gruntz Thesis</a>.</p>
</section>
<section id="reference">
<h4>Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h4>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.gruntz">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">gruntz</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">z0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L664-L707"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.gruntz" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the limit of e(z) at the point z0 using the Gruntz algorithm.</p>
<p class="rubric">Explanation</p>
<p><code class="docutils literal notranslate"><span class="pre">z0</span></code> can be any expression, including oo and -oo.</p>
<p>For <code class="docutils literal notranslate"><span class="pre">dir=&quot;+&quot;</span></code> (default) it calculates the limit from the right
(z-&gt;z0+) and for <code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;</span></code> the limit from the left (z-&gt;z0-). For infinite z0
(oo or -oo), the dir argument doesn’t matter.</p>
<p>This algorithm is fully described in the module docstring in the gruntz.py
file. It relies heavily on the series expansion. Most frequently, gruntz()
is only used if the faster limit() function (which uses heuristics) fails.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.compare">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">compare</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">a</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L135-L150"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.compare" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns “&lt;” if a&lt;b, “=” for a == b, “&gt;” for a&gt;b</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.rewrite">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">rewrite</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">Omega</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">wsym</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L590-L661"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.rewrite" title="Permalink to this definition">¶</a></dt>
<dd><p>e(x) … the function
Omega … the mrv set
wsym … the symbol which is going to be used for w</p>
<p>Returns the rewritten e in terms of w and log(w). See test_rewrite1()
for examples and correct results.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.build_expression_tree">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">build_expression_tree</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">Omega</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rewrites</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L553-L587"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.build_expression_tree" title="Permalink to this definition">¶</a></dt>
<dd><p>Helper function for rewrite.</p>
<p>We need to sort Omega (mrv set) so that we replace an expression before
we replace any expression in terms of which it has to be rewritten:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">e1</span> <span class="o">---&gt;</span> <span class="n">e2</span> <span class="o">---&gt;</span> <span class="n">e3</span>
         \
          <span class="o">-&gt;</span> <span class="n">e4</span>
</pre></div>
</div>
<p>Here we can do e1, e2, e3, e4 or e1, e2, e4, e3.
To do this we assemble the nodes into a tree, and sort them by height.</p>
<p>This function builds the tree, rewrites then sorts the nodes.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.mrv_leadterm">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">mrv_leadterm</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L509-L550"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.mrv_leadterm" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns (c0, e0) for e.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.calculate_series">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">calculate_series</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">logx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L483-L506"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.calculate_series" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculates at least one term of the series of <code class="docutils literal notranslate"><span class="pre">e</span></code> in <code class="docutils literal notranslate"><span class="pre">x</span></code>.</p>
<p>This is a place that fails most often, so it is in its own function.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.limitinf">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">limitinf</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">leadsimp</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L422-L467"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.limitinf" title="Permalink to this definition">¶</a></dt>
<dd><p>Limit e(x) for x-&gt; oo.</p>
<p class="rubric">Explanation</p>
<p>If <code class="docutils literal notranslate"><span class="pre">leadsimp</span></code> is True, an attempt is made to simplify the leading
term of the series expansion of <code class="docutils literal notranslate"><span class="pre">e</span></code>. That may succeed even if
<code class="docutils literal notranslate"><span class="pre">e</span></code> cannot be simplified.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.sign">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">sign</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L362-L419"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.sign" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a sign of an expression e(x) for x-&gt;oo.</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">e</span> <span class="o">&gt;</span>  <span class="mi">0</span> <span class="k">for</span> <span class="n">x</span> <span class="n">sufficiently</span> <span class="n">large</span> <span class="o">...</span>  <span class="mi">1</span>
<span class="n">e</span> <span class="o">==</span> <span class="mi">0</span> <span class="k">for</span> <span class="n">x</span> <span class="n">sufficiently</span> <span class="n">large</span> <span class="o">...</span>  <span class="mi">0</span>
<span class="n">e</span> <span class="o">&lt;</span>  <span class="mi">0</span> <span class="k">for</span> <span class="n">x</span> <span class="n">sufficiently</span> <span class="n">large</span> <span class="o">...</span> <span class="o">-</span><span class="mi">1</span>
</pre></div>
</div>
<p>The result of this function is currently undefined if e changes sign
arbitrarily often for arbitrarily large x (e.g. sin(x)).</p>
<p>Note that this returns zero only if e is <em>constantly</em> zero
for x sufficiently large. [If e is constant, of course, this is just
the same thing as the sign of e.]</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.mrv">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">mrv</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L245-L318"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.mrv" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a SubsSet of most rapidly varying (mrv) subexpressions of ‘e’,
and e rewritten in terms of these</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.mrv_max1">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">mrv_max1</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">g</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exps</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L350-L359"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.mrv_max1" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the maximum of two sets of expressions f and g, which
are in the same comparability class, i.e. mrv_max1() compares (two elements of)
f and g and returns the set, which is in the higher comparability class
of the union of both, if they have the same order of variation.
Also returns exps, with the appropriate substitutions made.</p>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.gruntz.mrv_max3">
<span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">mrv_max3</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">f</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expsf</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">g</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expsg</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">union</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">expsboth</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L321-L347"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.mrv_max3" title="Permalink to this definition">¶</a></dt>
<dd><p>Computes the maximum of two sets of expressions f and g, which
are in the same comparability class, i.e. max() compares (two elements of)
f and g and returns either (f, expsf) [if f is larger], (g, expsg)
[if g is larger] or (union, expsboth) [if f, g are of the same class].</p>
</dd></dl>

<dl class="py class">
<dt class="sig sig-object py" id="sympy.series.gruntz.SubsSet">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.series.gruntz.</span></span><span class="sig-name descname"><span class="pre">SubsSet</span></span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L153-L242"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.SubsSet" title="Permalink to this definition">¶</a></dt>
<dd><p>Stores (expr, dummy) pairs, and how to rewrite expr-s.</p>
<p class="rubric">Explanation</p>
<p>The gruntz algorithm needs to rewrite certain expressions in term of a new
variable w. We cannot use subs, because it is just too smart for us. For
example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">Omega</span><span class="o">=</span><span class="p">[</span><span class="n">exp</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">_p</span> <span class="o">-</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">_p</span><span class="p">))</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">_p</span><span class="p">)),</span> <span class="n">exp</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">_p</span><span class="p">))]</span>
<span class="o">&gt;</span> <span class="n">O2</span><span class="o">=</span><span class="p">[</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">exp</span><span class="p">(</span><span class="n">_p</span><span class="p">)</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">_p</span><span class="p">))</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="n">_p</span><span class="p">)</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">_p</span><span class="p">))</span><span class="o">/</span><span class="n">_w</span><span class="p">,</span> <span class="mi">1</span><span class="o">/</span><span class="n">_w</span><span class="p">]</span>
<span class="o">&gt;</span> <span class="n">e</span> <span class="o">=</span> <span class="n">exp</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">_p</span> <span class="o">-</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">_p</span><span class="p">))</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">_p</span><span class="p">))</span> <span class="o">-</span> <span class="n">exp</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">_p</span><span class="p">))</span>
<span class="o">&gt;</span> <span class="n">e</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">Omega</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span><span class="n">O2</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">Omega</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="n">O2</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>
<span class="o">-</span><span class="mi">1</span><span class="o">/</span><span class="n">w</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">exp</span><span class="p">(</span><span class="n">p</span><span class="p">)</span><span class="o">*</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">p</span><span class="p">))</span><span class="o">/</span><span class="p">(</span><span class="mi">1</span> <span class="o">-</span> <span class="mi">1</span><span class="o">/</span><span class="n">p</span><span class="p">))</span>
</pre></div>
</div>
<p>is really not what we want!</p>
<p>So we do it the hard way and keep track of all the things we potentially
want to substitute by dummy variables. Consider the expression:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">))</span> <span class="o">+</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="o">.</span>
</pre></div>
</div>
<p>The mrv set is {exp(x), exp(-x), exp(x - exp(-x))}.
We introduce corresponding dummy variables d1, d2, d3 and rewrite:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">d3</span> <span class="o">+</span> <span class="n">d1</span> <span class="o">+</span> <span class="n">x</span><span class="o">.</span>
</pre></div>
</div>
<p>This class first of all keeps track of the mapping expr-&gt;variable, i.e.
will at this stage be a dictionary:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="p">):</span> <span class="n">d1</span><span class="p">,</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">):</span> <span class="n">d2</span><span class="p">,</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span> <span class="o">-</span> <span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">x</span><span class="p">)):</span> <span class="n">d3</span><span class="p">}</span><span class="o">.</span>
</pre></div>
</div>
<p>[It turns out to be more convenient this way round.]
But sometimes expressions in the mrv set have other expressions from the
mrv set as subexpressions, and we need to keep track of that as well. In
this case, d3 is really exp(x - d2), so rewrites at this stage is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="n">d3</span><span class="p">:</span> <span class="n">exp</span><span class="p">(</span><span class="n">x</span><span class="o">-</span><span class="n">d2</span><span class="p">)}</span><span class="o">.</span>
</pre></div>
</div>
<p>The function rewrite uses all this information to correctly rewrite our
expression in terms of w. In this case w can be chosen to be exp(-x),
i.e. d2. The correct rewriting then is:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">exp</span><span class="p">(</span><span class="o">-</span><span class="n">w</span><span class="p">)</span><span class="o">/</span><span class="n">w</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">w</span> <span class="o">+</span> <span class="n">x</span><span class="o">.</span>
</pre></div>
</div>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.series.gruntz.SubsSet.copy">
<span class="sig-name descname"><span class="pre">copy</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L236-L242"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.SubsSet.copy" title="Permalink to this definition">¶</a></dt>
<dd><p>Create a shallow copy of SubsSet</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.series.gruntz.SubsSet.do_subs">
<span class="sig-name descname"><span class="pre">do_subs</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">e</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L211-L215"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.SubsSet.do_subs" title="Permalink to this definition">¶</a></dt>
<dd><p>Substitute the variables with expressions</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.series.gruntz.SubsSet.meets">
<span class="sig-name descname"><span class="pre">meets</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s2</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L217-L219"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.SubsSet.meets" title="Permalink to this definition">¶</a></dt>
<dd><p>Tell whether or not self and s2 have non-empty intersection</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.series.gruntz.SubsSet.union">
<span class="sig-name descname"><span class="pre">union</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">s2</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">exps</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/gruntz.py#L221-L234"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.gruntz.SubsSet.union" title="Permalink to this definition">¶</a></dt>
<dd><p>Compute the union of self and s2, adjusting exps</p>
</dd></dl>

</dd></dl>

</section>
</section>
</section>
<section id="more-intuitive-series-expansion">
<h2>More Intuitive Series Expansion<a class="headerlink" href="#more-intuitive-series-expansion" title="Permalink to this headline">¶</a></h2>
<p>This is achieved
by creating a wrapper around Basic.series(). This allows for the use of
series(x*cos(x),x), which is possibly more intuitive than (x*cos(x)).series(x).</p>
<section id="examples">
<h3>Examples<a class="headerlink" href="#examples" title="Permalink to this headline">¶</a></h3>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">series</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">series</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">),</span><span class="n">x</span><span class="p">)</span>
<span class="go">1 - x**2/2 + x**4/24 + O(x**6)</span>
</pre></div>
</div>
</section>
<section id="id2">
<h3>Reference<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.series.series">
<span class="sig-prename descclassname"><span class="pre">sympy.series.series.</span></span><span class="sig-name descname"><span class="pre">series</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">6</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'+'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/series.py#L4-L63"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.series.series" title="Permalink to this definition">¶</a></dt>
<dd><p>Series expansion of expr around point <span class="math notranslate nohighlight">\(x = x0\)</span>.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>expr</strong> : Expression</p>
<blockquote>
<div><p>The expression whose series is to be expanded.</p>
</div></blockquote>
<p><strong>x</strong> : Symbol</p>
<blockquote>
<div><p>It is the variable of the expression to be calculated.</p>
</div></blockquote>
<p><strong>x0</strong> : Value</p>
<blockquote>
<div><p>The value around which <code class="docutils literal notranslate"><span class="pre">x</span></code> is calculated. Can be any value
from <code class="docutils literal notranslate"><span class="pre">-oo</span></code> to <code class="docutils literal notranslate"><span class="pre">oo</span></code>.</p>
</div></blockquote>
<p><strong>n</strong> : Value</p>
<blockquote>
<div><p>The number of terms upto which the series is to be expanded.</p>
</div></blockquote>
<p><strong>dir</strong> : String, optional</p>
<blockquote>
<div><p>The series-expansion can be bi-directional. If <code class="docutils literal notranslate"><span class="pre">dir=&quot;+&quot;</span></code>,
then (x-&gt;x0+). If <code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;,</span> <span class="pre">then</span> <span class="pre">(x-&gt;x0-).</span> <span class="pre">For</span> <span class="pre">infinite</span>
<span class="pre">``x0</span></code> (<code class="docutils literal notranslate"><span class="pre">oo</span></code> or <code class="docutils literal notranslate"><span class="pre">-oo</span></code>), the <code class="docutils literal notranslate"><span class="pre">dir</span></code> argument is determined
from the direction of the infinity (i.e., <code class="docutils literal notranslate"><span class="pre">dir=&quot;-&quot;</span></code> for
<code class="docutils literal notranslate"><span class="pre">oo</span></code>).</p>
</div></blockquote>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>Expr</p>
<blockquote>
<div><p>Series expansion of the expression about x0</p>
</div></blockquote>
</dd>
</dl>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">series</span><span class="p">,</span> <span class="n">tan</span><span class="p">,</span> <span class="n">oo</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">f</span> <span class="o">=</span> <span class="n">tan</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">series</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="s2">&quot;+&quot;</span><span class="p">)</span>
<span class="go">tan(2) + (1 + tan(2)**2)*(x - 2) + (x - 2)**2*(tan(2)**3 + tan(2)) +</span>
<span class="go">(x - 2)**3*(1/3 + 4*tan(2)**2/3 + tan(2)**4) + (x - 2)**4*(tan(2)**5 +</span>
<span class="go">5*tan(2)**3/3 + 2*tan(2)/3) + (x - 2)**5*(2/15 + 17*tan(2)**2/15 +</span>
<span class="go">2*tan(2)**4 + tan(2)**6) + O((x - 2)**6, (x, 2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">series</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">&quot;-&quot;</span><span class="p">)</span>
<span class="go">tan(2) + (2 - x)*(-tan(2)**2 - 1) + (2 - x)**2*(tan(2)**3 + tan(2))</span>
<span class="go">+ O((x - 2)**3, (x, 2))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">series</span><span class="p">(</span><span class="n">f</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="s2">&quot;+&quot;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">TypeError</span>: <span class="n">&#39;Infinity&#39; object cannot be interpreted as an integer</span>
</pre></div>
</div>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="../core.html#sympy.core.expr.Expr.series" title="sympy.core.expr.Expr.series"><code class="xref py py-obj docutils literal notranslate"><span class="pre">sympy.core.expr.Expr.series</span></code></a></dt><dd><p>See the docstring of Expr.series() for complete details of this wrapper.</p>
</dd>
</dl>
</div>
</dd></dl>

</section>
</section>
<section id="order-terms">
<h2>Order Terms<a class="headerlink" href="#order-terms" title="Permalink to this headline">¶</a></h2>
<p>This module also implements automatic keeping track of the order of your
expansion.</p>
<section id="id3">
<h3>Examples<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h3>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">Order</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s1">&#39;x&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span>
<span class="go">O(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">Order</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span>
<span class="go">1 + O(x)</span>
</pre></div>
</div>
</section>
<section id="id4">
<h3>Reference<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h3>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.series.order.Order">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.series.order.</span></span><span class="sig-name descname"><span class="pre">Order</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/order.py#L10-L505"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.order.Order" title="Permalink to this definition">¶</a></dt>
<dd><p>Represents the limiting behavior of some function.</p>
<p class="rubric">Explanation</p>
<p>The order of a function characterizes the function based on the limiting
behavior of the function as it goes to some limit. Only taking the limit
point to be a number is currently supported. This is expressed in
big O notation <a class="reference internal" href="#r686" id="id5"><span>[R686]</span></a>.</p>
<p>The formal definition for the order of a function <span class="math notranslate nohighlight">\(g(x)\)</span> about a point <span class="math notranslate nohighlight">\(a\)</span>
is such that <span class="math notranslate nohighlight">\(g(x) = O(f(x))\)</span> as <span class="math notranslate nohighlight">\(x \rightarrow a\)</span> if and only if for any
<span class="math notranslate nohighlight">\(\delta &gt; 0\)</span> there exists a <span class="math notranslate nohighlight">\(M &gt; 0\)</span> such that <span class="math notranslate nohighlight">\(|g(x)| \leq M|f(x)|\)</span> for
<span class="math notranslate nohighlight">\(|x-a| &lt; \delta\)</span>.  This is equivalent to <span class="math notranslate nohighlight">\(\lim_{x \rightarrow a}
\sup |g(x)/f(x)| &lt; \infty\)</span>.</p>
<p>Let’s illustrate it on the following example by taking the expansion of
<span class="math notranslate nohighlight">\(\sin(x)\)</span> about 0:</p>
<div class="math notranslate nohighlight">
\[\sin(x) = x - x^3/3! + O(x^5)\]</div>
<p>where in this case <span class="math notranslate nohighlight">\(O(x^5) = x^5/5! - x^7/7! + \cdots\)</span>. By the definition
of <span class="math notranslate nohighlight">\(O\)</span>, for any <span class="math notranslate nohighlight">\(\delta &gt; 0\)</span> there is an <span class="math notranslate nohighlight">\(M\)</span> such that:</p>
<div class="math notranslate nohighlight">
\[|x^5/5! - x^7/7! + ....| &lt;= M|x^5| \text{ for } |x| &lt; \delta\]</div>
<p>or by the alternate definition:</p>
<div class="math notranslate nohighlight">
\[\lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| &lt; \infty\]</div>
<p>which surely is true, because</p>
<div class="math notranslate nohighlight">
\[\lim_{x \rightarrow 0} | (x^5/5! - x^7/7! + ....) / x^5| = 1/5!\]</div>
<p>As it is usually used, the order of a function can be intuitively thought
of representing all terms of powers greater than the one specified. For
example, <span class="math notranslate nohighlight">\(O(x^3)\)</span> corresponds to any terms proportional to <span class="math notranslate nohighlight">\(x^3,
x^4,\ldots\)</span> and any higher power. For a polynomial, this leaves terms
proportional to <span class="math notranslate nohighlight">\(x^2\)</span>, <span class="math notranslate nohighlight">\(x\)</span> and constants.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">O</span><span class="p">,</span> <span class="n">oo</span><span class="p">,</span> <span class="n">cos</span><span class="p">,</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">x</span><span class="p">,</span> <span class="n">y</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">O(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">O(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span> <span class="o">+</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">O(x**2, (x, oo))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">)</span>
<span class="go">O(1, x, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
<span class="go">O(1, x, y)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="n">x</span><span class="o">*</span><span class="n">y</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">oo</span><span class="p">),</span> <span class="p">(</span><span class="n">y</span><span class="p">,</span> <span class="n">oo</span><span class="p">))</span>
<span class="go">O(x*y, (x, oo), (y, oo))</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="ow">in</span> <span class="n">O</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span> <span class="ow">in</span> <span class="n">O</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="ow">in</span> <span class="n">O</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span> <span class="ow">in</span> <span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">True</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="p">)</span><span class="o">*</span><span class="n">x</span>
<span class="go">O(x**2)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="p">)</span> <span class="o">-</span> <span class="n">O</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
<span class="go">O(x)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">))</span>
<span class="go">O(1)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">O</span><span class="p">(</span><span class="n">cos</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">pi</span><span class="o">/</span><span class="mi">2</span><span class="p">))</span>
<span class="go">O(x - pi/2, (x, pi/2))</span>
</pre></div>
</div>
<p class="rubric">Notes</p>
<p>In <code class="docutils literal notranslate"><span class="pre">O(f(x),</span> <span class="pre">x)</span></code> the expression <code class="docutils literal notranslate"><span class="pre">f(x)</span></code> is assumed to have a leading
term.  <code class="docutils literal notranslate"><span class="pre">O(f(x),</span> <span class="pre">x)</span></code> is automatically transformed to
<code class="docutils literal notranslate"><span class="pre">O(f(x).as_leading_term(x),x)</span></code>.</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">O(expr*f(x),</span> <span class="pre">x)</span></code> is <code class="docutils literal notranslate"><span class="pre">O(f(x),</span> <span class="pre">x)</span></code></p>
<p><code class="docutils literal notranslate"><span class="pre">O(expr,</span> <span class="pre">x)</span></code> is <code class="docutils literal notranslate"><span class="pre">O(1)</span></code></p>
<p><code class="docutils literal notranslate"><span class="pre">O(0,</span> <span class="pre">x)</span></code> is 0.</p>
</div></blockquote>
<p>Multivariate O is also supported:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">O(f(x,</span> <span class="pre">y),</span> <span class="pre">x,</span> <span class="pre">y)</span></code> is transformed to
<code class="docutils literal notranslate"><span class="pre">O(f(x,</span> <span class="pre">y).as_leading_term(x,y).as_leading_term(y),</span> <span class="pre">x,</span> <span class="pre">y)</span></code></p>
</div></blockquote>
<p>In the multivariate case, it is assumed the limits w.r.t. the various
symbols commute.</p>
<p>If no symbols are passed then all symbols in the expression are used
and the limit point is assumed to be zero.</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r686"><span class="brackets">R686</span><span class="fn-backref">(<a href="#id5">1</a>,<a href="#id6">2</a>)</span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Big_O_notation">Big O notation</a></p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="sympy.series.order.Order.contains">
<span class="sig-name descname"><span class="pre">contains</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/order.py#L365-L443"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.order.Order.contains" title="Permalink to this definition">¶</a></dt>
<dd><p>Return True if expr belongs to Order(self.expr, *self.variables).
Return False if self belongs to expr.
Return None if the inclusion relation cannot be determined
(e.g. when self and expr have different symbols).</p>
</dd></dl>

</dd></dl>

</section>
</section>
<section id="series-acceleration">
<h2>Series Acceleration<a class="headerlink" href="#series-acceleration" title="Permalink to this headline">¶</a></h2>
<p>TODO</p>
<section id="id7">
<h3>Reference<a class="headerlink" href="#id7" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.acceleration.richardson">
<span class="sig-prename descclassname"><span class="pre">sympy.series.acceleration.</span></span><span class="sig-name descname"><span class="pre">richardson</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">A</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">N</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/acceleration.py#L15-L66"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.acceleration.richardson" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate an approximation for lim k-&gt;oo A(k) using Richardson
extrapolation with the terms A(n), A(n+1), …, A(n+N+1).
Choosing N ~= 2*n often gives good results.</p>
<p class="rubric">Examples</p>
<p>A simple example is to calculate exp(1) using the limit definition.
This limit converges slowly; n = 100 only produces two accurate
digits:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">e</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="mi">1</span><span class="o">/</span><span class="n">n</span><span class="p">)</span><span class="o">**</span><span class="n">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">2.7048138294</span>
</pre></div>
</div>
<p>Richardson extrapolation with 11 appropriately chosen terms gives
a value that is accurate to the indicated precision:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">E</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.series.acceleration</span> <span class="kn">import</span> <span class="n">richardson</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">richardson</span><span class="p">(</span><span class="n">e</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">2.7182818285</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">E</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">2.7182818285</span>
</pre></div>
</div>
<p>Another useful application is to speed up convergence of series.
Computing 100 terms of the zeta(2) series 1/k**2 yields only
two accurate digits:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">k</span><span class="p">,</span> <span class="n">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">k</span><span class="o">**-</span><span class="mi">2</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">1.6349839002</span>
</pre></div>
</div>
<p>Richardson extrapolation performs much better:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">pi</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">richardson</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="mi">20</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">1.6449340668</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(((</span><span class="n">pi</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span><span class="o">/</span><span class="mi">6</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>     <span class="c1"># Exact value</span>
<span class="go">1.6449340668</span>
</pre></div>
</div>
</dd></dl>

<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.acceleration.shanks">
<span class="sig-prename descclassname"><span class="pre">sympy.series.acceleration.</span></span><span class="sig-name descname"><span class="pre">shanks</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">A</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">n</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">m</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/acceleration.py#L69-L99"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.acceleration.shanks" title="Permalink to this definition">¶</a></dt>
<dd><p>Calculate an approximation for lim k-&gt;oo A(k) using the n-term Shanks
transformation S(A)(n). With m &gt; 1, calculate the m-fold recursive
Shanks transformation S(S(…S(A)…))(n).</p>
<p>The Shanks transformation is useful for summing Taylor series that
converge slowly near a pole or singularity, e.g. for log(2):</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.abc</span> <span class="kn">import</span> <span class="n">k</span><span class="p">,</span> <span class="n">n</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Sum</span><span class="p">,</span> <span class="n">Integer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.series.acceleration</span> <span class="kn">import</span> <span class="n">shanks</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">A</span> <span class="o">=</span> <span class="n">Sum</span><span class="p">(</span><span class="n">Integer</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">**</span><span class="p">(</span><span class="n">k</span><span class="o">+</span><span class="mi">1</span><span class="p">)</span> <span class="o">/</span> <span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">n</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">A</span><span class="o">.</span><span class="n">subs</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="mi">100</span><span class="p">)</span><span class="o">.</span><span class="n">doit</span><span class="p">()</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">0.6881721793</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">shanks</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">25</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">0.6931396564</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span><span class="p">(</span><span class="nb">round</span><span class="p">(</span><span class="n">shanks</span><span class="p">(</span><span class="n">A</span><span class="p">,</span> <span class="n">n</span><span class="p">,</span> <span class="mi">25</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span><span class="o">.</span><span class="n">evalf</span><span class="p">(),</span> <span class="mi">10</span><span class="p">))</span>
<span class="go">0.6931471806</span>
</pre></div>
</div>
<p>The correct value is 0.6931471805599453094172321215.</p>
</dd></dl>

</section>
</section>
<section id="residues">
<h2>Residues<a class="headerlink" href="#residues" title="Permalink to this headline">¶</a></h2>
<p>TODO</p>
<section id="id8">
<h3>Reference<a class="headerlink" href="#id8" title="Permalink to this headline">¶</a></h3>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.series.residues.residue">
<span class="sig-prename descclassname"><span class="pre">sympy.series.residues.</span></span><span class="sig-name descname"><span class="pre">residue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">x0</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/series/residues.py#L10-L70"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.series.residues.residue" title="Permalink to this definition">¶</a></dt>
<dd><p>Finds the residue of <code class="docutils literal notranslate"><span class="pre">expr</span></code> at the point x=x0.</p>
<p>The residue is defined as the coefficient of <code class="docutils literal notranslate"><span class="pre">1/(x-x0)</span></code> in the power series
expansion about <code class="docutils literal notranslate"><span class="pre">x=x0</span></code>.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy</span> <span class="kn">import</span> <span class="n">Symbol</span><span class="p">,</span> <span class="n">residue</span><span class="p">,</span> <span class="n">sin</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">x</span> <span class="o">=</span> <span class="n">Symbol</span><span class="p">(</span><span class="s2">&quot;x&quot;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">residue</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">residue</span><span class="p">(</span><span class="mi">1</span><span class="o">/</span><span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">0</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">residue</span><span class="p">(</span><span class="mi">2</span><span class="o">/</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span> <span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
<span class="go">2</span>
</pre></div>
</div>
<p>This function is essential for the Residue Theorem [1].</p>
<p class="rubric">References</p>
<dl class="citation">
<dt class="label" id="r687"><span class="brackets"><a class="fn-backref" href="#id9">R687</a></span></dt>
<dd><p><a class="reference external" href="https://en.wikipedia.org/wiki/Residue_theorem">https://en.wikipedia.org/wiki/Residue_theorem</a></p>
</dd>
</dl>
</dd></dl>

</section>
</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../index.html">
              <img class="logo" src="../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Series Expansions</a><ul>
<li><a class="reference internal" href="#limits">Limits</a><ul>
<li><a class="reference internal" href="#the-gruntz-algorithm">The Gruntz Algorithm</a><ul>
<li><a class="reference internal" href="#notes">Notes</a></li>
<li><a class="reference internal" href="#reference">Reference</a></li>
</ul>
</li>
</ul>
</li>
<li><a class="reference internal" href="#more-intuitive-series-expansion">More Intuitive Series Expansion</a><ul>
<li><a class="reference internal" href="#examples">Examples</a></li>
<li><a class="reference internal" href="#id2">Reference</a></li>
</ul>
</li>
<li><a class="reference internal" href="#order-terms">Order Terms</a><ul>
<li><a class="reference internal" href="#id3">Examples</a></li>
<li><a class="reference internal" href="#id4">Reference</a></li>
</ul>
</li>
<li><a class="reference internal" href="#series-acceleration">Series Acceleration</a><ul>
<li><a class="reference internal" href="#id7">Reference</a></li>
</ul>
</li>
<li><a class="reference internal" href="#residues">Residues</a><ul>
<li><a class="reference internal" href="#id8">Reference</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="index.html"
                        title="previous chapter">Series</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="sequences.html"
                        title="next chapter">Sequences</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../_sources/modules/series/series.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="sequences.html" title="Sequences"
             >next</a> |</li>
        <li class="right" >
          <a href="index.html" title="Series"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="index.html" >Series</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Series Expansions</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/series/series.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:28:17 GMT -->
</html>